﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using QuanLyNhaSach.QuanLyNhaSachDTO;

namespace QuanLyNhaSach.QuanLyNhaSachDao
{
    class HoaDonDao
    {
        public static DataTable GetHoaDonAll()
        {
            string sql = "select * from HoaDon where Active=True";
            return Database.ExcuQuery(sql);
        }

        public static DataTable GetHoaDonTheoMaHD(int s)
        {
            int a = s;
            string sql = "select * from HoaDon where Active=True and MaHoaDon = " + a + "";
            return Database.ExcuQuery(sql);
        }
        public static bool Insert(HoaDonDTO tl)
        {
            string sql;
            bool active = true;
            sql = "insert into HoaDon(MaKhachHang,NgayLap,Active) values('" + tl.MaKhachHang + "','" + tl.NgayLap + "'," + active + ")";
            Database.ExcuNonQuery(sql);
            return true;

        }
        public static void Delete(HoaDonDTO tl)
        {
            // bool active = false;
            string sql = "Delete from  HoaDon where MaHoaDon=" + tl.MaHoaDon + "";

            Database.ExcuNonQuery(sql);
        }
        public static bool Update(HoaDonDTO tl)
        {
            string sql = "Update HoaDon set NgayLap = ('" + tl.NgayLap + "'), MaKhachHang = ('" + tl.MaKhachHang + "') where MaHoaDon = " + tl.MaHoaDon + "";

            Database.ExcuNonQuery(sql);
            return true;
        }
        public static int KTTienNo(HoaDonDTO tl)
        {
            

            string sql = "select TienNo from KhachHang where MaKhachHang=" + tl.MaKhachHang + "";
            DataTable dt = Database.ExcuQuery(sql);
            int e = int.Parse(dt.Rows[0]["TienNo"].ToString());
            return e;
        }
    }
}
